﻿namespace Bridge.Base.Converter
{
    using System;
    using System.Collections.Generic;
    using Bridge.Base.Constructs;

    /// <summary>
    /// Constructor for implementing a PossibleUriFinder
    /// </summary>
    public abstract class PossibleUriFinder
    {
        /// <summary>
        /// Gets the <see cref="Type"/> of <see cref="Character"/> that this finder locates.
        /// </summary>
        /// <returns><see cref="Type"/> of <see cref="Character"/> that this finder locates.</returns>
        public abstract Type GetCharacterType();

        /// <summary>
        /// Gets all of the possible <see cref="Uri"/>s from this converter.
        /// </summary>
        /// <returns>Dictionary of possible <see cref="Uri"/>s found.</returns>
        public abstract Dictionary<string, Uri> GetAllPossibleUris();

        /// <summary>
        /// Gets the compatible <see cref="UriConverter"/>s that can convert the information found.
        /// </summary>
        /// <returns>List of <see cref="UriConverter"/>s that can convert the information found.</returns>
        public abstract IEnumerable<UriConverter> GetCompatibleBaseConverters();

        /// <summary>
        /// Gets the default <see cref="UriConverter"/> to convert the information.
        /// </summary>
        public abstract UriConverter DefaultBaseConverter { get; }
    }

    /// <summary>
    /// Interface for finding Possible Uris for the converter to run.
    /// </summary>
    /// <typeparam name="T"><see cref="Character"/> that this implements.</typeparam>
    public abstract class PossibleUriFinder<T> : PossibleUriFinder where T : Character
    {
        /// <summary>
        /// Gets the <see cref="Type"/> of <see cref="Character"/> that this finder locates.
        /// </summary>
        /// <returns><see cref="Type"/> of <see cref="Character"/> that this finder locates.</returns>
        public override Type GetCharacterType()
        {
            return typeof(T);
        }


        /// <summary>
        /// Gets the compatible <see cref="UriConverter"/>s that can convert the information found.
        /// </summary>
        /// <returns>List of <see cref="UriConverter"/>s that can convert the information found.</returns>
        public override IEnumerable<UriConverter> GetCompatibleBaseConverters()
        {
            List<UriConverter> converters = new List<UriConverter>();
            foreach (UriConverter<T> converter in GetCompatibleConverters())
            {
                converters.Add(converter);
            }
            return converters;
        }

        /// <summary>
        /// Gets the default <see cref="UriConverter"/> to convert the information.
        /// </summary>
        public override UriConverter DefaultBaseConverter
        {
            get { return DefaultConverter; }
        }

        /// <summary>
        /// Gets the default <see cref="UriConverter{T}"/> to convert the information.
        /// </summary>
        public abstract UriConverter<T> DefaultConverter { get; }

        /// <summary>
        /// Gets the compatible <see cref="UriConverter{T}"/>s that can convert the information found.
        /// </summary>
        /// <returns>List of <see cref="UriConverter{T}"/>s that can convert the information found.</returns>
        public abstract IEnumerable<UriConverter<T>> GetCompatibleConverters();
    }
}
